library(rstan)
library(survival)
library(tidyverse)
library(tidybayes)
# data, parameters, model and generated quantities blocks
Stan_exponential_survival_model <- "
data{
  int <lower=1> N_uncensored;
  int <lower=1> N_censored;
  int <lower=0> numCovariates;
  matrix[N_censored, numCovariates] X_censored;
  matrix[N_uncensored, numCovariates] X_uncensored;
  vector <lower=0>[N_censored] times_censored;
  vector <lower=0>[N_uncensored] times_uncensored;
}

parameters{
  vector[numCovariates] beta; //regression coefficients
  real alpha; //intercept
}

model{
  beta ~ normal(0,10); //prior on regression coefficients
  alpha ~ normal(0,10); //prior on intercept
  target += exponential_lpdf(times_uncensored | exp(alpha+X_uncensored * beta)); //log-likelihood part for uncensored times
  target += exponential_lccdf(times_censored | exp(alpha+X_censored * beta)); //log-likelihood for censored times
}

generated quantities{
  vector[N_uncensored] times_uncensored_sampled; //prediction of death
  for(i in 1:N_uncensored) {
    times_uncensored_sampled[i] = exponential_rng(exp(alpha+X_uncensored[i,]* beta));
  }
}
"
# prepare the data
set.seed(42); 
require (tidyverse);
data <- read_csv('../data.csv')
New names:
* `` -> ...1
Rows: 2066 Columns: 12
── Column specification ───────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (3): url, host_type, project
dbl (8): ...1, major_releases, duration, author_count, rev_count, status, multi_repo, commits_per_day
lgl (1): commit_freq_above_median

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
N <- nrow (data); 
X <- as.matrix(pull(data, multi_repo)); 
is_censored <- pull(data, status)==0; 
times <- pull(data, duration); 
msk_censored <- is_censored == 1; 
N_censored <- sum(msk_censored);
# put data into a list for Stan
Stan_data <- list (N_uncensored = N - N_censored, 
                    N_censored = N_censored,
                    numCovariates = ncol(X), 
                    X_censored = as.matrix(X[msk_censored,]),
                    X_uncensored = as.matrix(X[!msk_censored ,]), 
                    times_censored = times[msk_censored],
                    times_uncensored = times[!msk_censored])
# fit Stan model
require(rstan)
exp_surv_model_fit <- suppressMessages(stan(model_code = Stan_exponential_survival_model, data = Stan_data))
Warning in system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  error in running command
clang: error: no input files

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000344 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.44 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 1.01969 seconds (Warm-up)
Chain 1:                0.963912 seconds (Sampling)
Chain 1:                1.9836 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 0.000167 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 1.67 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 0.979266 seconds (Warm-up)
Chain 2:                0.977952 seconds (Sampling)
Chain 2:                1.95722 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 0.000167 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 1.67 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 0.973601 seconds (Warm-up)
Chain 3:                0.89372 seconds (Sampling)
Chain 3:                1.86732 seconds (Total)
Chain 3: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 4).
Chain 4: 
Chain 4: Gradient evaluation took 0.000172 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 1.72 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4: 
Chain 4: 
Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 4: 
Chain 4:  Elapsed Time: 0.95383 seconds (Warm-up)
Chain 4:                0.827181 seconds (Sampling)
Chain 4:                1.78101 seconds (Total)
Chain 4: 
# print model fit
print(get_seed(exp_surv_model_fit))
[1] 1781592037
# print fit summary
fit_summary <- summary(exp_surv_model_fit)
print(fit_summary$summary)
                                      mean      se_mean           sd         2.5%          25%          50%
beta[1]                          -1.201176 0.0048332048   0.24669382    -1.715388    -1.365972    -1.190598
alpha                            -4.946324 0.0007286265   0.03972408    -5.024545    -4.973130    -4.946488
times_uncensored_sampled[1]     141.666065 2.3767378381 145.38910208     3.491004    38.549715    95.291852
times_uncensored_sampled[2]     138.878612 2.2296597711 139.56783291     4.474014    39.587905    95.060079
times_uncensored_sampled[3]     144.084841 2.2885804108 146.24543106     3.616957    41.340714    98.868689
times_uncensored_sampled[4]     141.185140 2.2301422457 142.77808281     3.655603    41.098360    98.699825
times_uncensored_sampled[5]     141.286374 2.1645269957 136.98699892     3.473791    42.577496    99.643133
times_uncensored_sampled[6]     139.741502 2.2387923200 142.01027816     3.045270    40.373978    95.083773
times_uncensored_sampled[7]     132.920417 2.1021205882 129.81231582     3.495246    37.728827    93.007772
times_uncensored_sampled[8]     140.060757 2.3153564645 144.68349049     3.326325    37.982147    94.256142
times_uncensored_sampled[9]     140.176585 2.2699092376 142.07812049     3.358885    38.220064    98.859483
times_uncensored_sampled[10]    138.084301 2.1927723385 137.93079440     3.255770    39.475986    96.255466
times_uncensored_sampled[11]    141.357451 2.2456942405 139.98639317     3.247370    39.386826   100.154973
times_uncensored_sampled[12]    140.086411 2.1588488938 137.17803595     4.231262    40.080520    97.799603
times_uncensored_sampled[13]    136.594242 2.2444836051 140.17106767     2.828577    37.670648    93.450522
times_uncensored_sampled[14]    141.875485 2.2989188661 143.97144392     3.828185    40.426656    97.799853
times_uncensored_sampled[15]    140.810964 2.2891163215 141.76372476     3.242956    39.601679    97.949931
times_uncensored_sampled[16]    141.005701 2.2657007521 142.65745586     2.964366    39.347522    95.191537
times_uncensored_sampled[17]    139.784478 2.3238378350 139.43878420     3.449323    40.753544    96.516142
times_uncensored_sampled[18]    141.157066 2.2281256028 143.45266938     2.873292    39.405969    96.164628
times_uncensored_sampled[19]    142.327983 2.2615373620 140.71949831     4.066908    41.155285    97.529493
times_uncensored_sampled[20]    143.131125 2.2325539981 142.31528805     3.719602    42.874640   100.447480
times_uncensored_sampled[21]    140.801308 2.2009512234 139.80536080     3.949775    40.468617    98.952540
times_uncensored_sampled[22]    482.120168 8.0622126693 504.69100419    11.492967   132.884552   323.942419
times_uncensored_sampled[23]    141.114519 2.2779014711 143.67112735     3.043007    40.647998    96.810141
times_uncensored_sampled[24]    144.280766 2.2542619766 142.84646258     2.843033    41.455397   101.172537
times_uncensored_sampled[25]    140.228878 2.2131644007 138.69802510     3.000487    41.855176    99.652053
times_uncensored_sampled[26]    143.097397 2.2745364221 142.82781832     3.470099    41.137559    98.176862
times_uncensored_sampled[27]    139.579791 2.1810112576 140.68725015     4.032686    40.427976    96.618287
times_uncensored_sampled[28]    139.862897 2.3134301693 139.05479099     3.231900    38.963067   100.025420
times_uncensored_sampled[29]    139.457136 2.1180398215 137.28519094     3.455785    39.669927    99.972725
times_uncensored_sampled[30]    142.100915 2.2739159056 142.09046220     4.093291    42.119051    98.314969
times_uncensored_sampled[31]    140.917267 2.1451230511 136.73748898     3.594980    42.349662   102.756844
times_uncensored_sampled[32]    142.040992 2.1795899993 138.14819528     3.625029    42.493164   102.807818
times_uncensored_sampled[33]    142.943524 2.3670119970 144.80793175     3.361040    41.413052    99.587906
times_uncensored_sampled[34]    137.905152 2.1736459377 139.67667770     4.501642    40.017265    95.126271
times_uncensored_sampled[35]    142.417453 2.3270603428 141.04000313     3.768097    41.754004    98.457498
times_uncensored_sampled[36]    143.544963 2.2459534021 144.32366357     3.906894    39.246786    99.501975
times_uncensored_sampled[37]    141.576356 2.2748172890 141.65392449     4.339499    40.202467    98.398429
times_uncensored_sampled[38]    142.120422 2.2652935303 143.32457241     2.909242    41.495026    96.833013
times_uncensored_sampled[39]    144.163058 2.3670145626 145.39540222     3.653107    40.431288    96.401371
times_uncensored_sampled[40]    139.213215 2.2042465077 138.68544692     4.525265    39.587609    97.507297
times_uncensored_sampled[41]    141.147144 2.3003370644 142.48426675     3.252929    41.080354    96.790155
times_uncensored_sampled[42]    139.938426 2.3554226915 145.71951706     3.863699    39.187542    94.689836
times_uncensored_sampled[43]    143.695793 2.3000327323 145.96810741     3.530737    41.044450    99.038842
times_uncensored_sampled[44]    141.308024 2.2382329316 138.71814900     3.869658    42.081540   101.476836
times_uncensored_sampled[45]    142.248264 2.3146859269 146.10204348     3.748352    39.962389    96.941135
times_uncensored_sampled[46]    143.368389 2.2389785271 141.99163310     3.020732    39.908355    98.602428
times_uncensored_sampled[47]    137.470311 2.1974761753 134.13808859     3.860213    41.570876    98.076682
times_uncensored_sampled[48]    140.158646 2.3117331348 142.36381852     3.210394    40.881687    96.966744
times_uncensored_sampled[49]    135.072998 2.2334825767 137.41380715     3.145728    37.548924    92.831917
times_uncensored_sampled[50]    141.907639 2.2768435519 142.25594617     3.479607    39.845276   101.554060
times_uncensored_sampled[51]    145.227746 2.3819285941 147.09770925     4.924185    40.242560    99.837592
times_uncensored_sampled[52]    139.493598 2.3437007357 142.88602492     3.041570    38.893033    95.775486
times_uncensored_sampled[53]    137.305408 2.1301757684 135.81506841     4.093309    40.676282    95.844352
times_uncensored_sampled[54]    144.064204 2.1828581629 140.57859735     4.202244    44.347497    99.919161
times_uncensored_sampled[55]    141.778274 2.2226858077 139.06499823     3.174115    42.696772   100.387588
times_uncensored_sampled[56]    140.950996 2.1835354136 139.31112350     3.834732    38.594049    97.552082
times_uncensored_sampled[57]    141.473647 2.3140071604 139.71177352     3.315157    40.408704    98.414264
times_uncensored_sampled[58]    141.069184 2.2989364060 142.79992139     3.734667    40.881487    96.727333
times_uncensored_sampled[59]    142.571892 2.2264643489 143.92739960     3.002375    40.549000    97.999353
times_uncensored_sampled[60]    141.684232 2.3281006564 142.77653664     3.677932    41.125468    97.945514
times_uncensored_sampled[61]    140.439094 2.2084997290 140.61666058     3.215852    39.731738    97.006842
times_uncensored_sampled[62]    141.855469 2.2828457900 144.48653368     3.715743    41.084327    99.061689
times_uncensored_sampled[63]    141.511545 2.2242155382 139.97120791     3.722338    40.232033   100.117981
times_uncensored_sampled[64]    144.768241 2.3492410881 147.57335054     3.523406    42.112396    99.577577
times_uncensored_sampled[65]    142.113890 2.3049086011 142.84272950     4.113509    41.321736    97.645956
times_uncensored_sampled[66]    142.715661 2.2881652259 143.06021844     4.204077    39.250185    97.529467
times_uncensored_sampled[67]    141.717587 2.2255718832 142.23956081     3.536500    41.382368    98.759014
times_uncensored_sampled[68]    138.622177 2.1286261977 135.83689639     4.286625    39.974760    98.809468
times_uncensored_sampled[69]    138.205831 2.1334740424 136.06999988     3.652522    37.936798    94.049764
times_uncensored_sampled[70]    139.151971 2.0844619834 134.92426439     3.596989    41.030085    99.875286
times_uncensored_sampled[71]    141.716863 2.2751753739 141.23832481     3.429824    40.000302    99.410814
times_uncensored_sampled[72]    140.354219 2.2618460882 140.19847020     3.073971    39.094108    99.934982
times_uncensored_sampled[73]    139.058467 2.1599409915 138.87372685     3.014968    39.155441    95.281408
times_uncensored_sampled[74]    140.264243 2.2468371920 140.88963800     3.254884    39.102908    97.661172
times_uncensored_sampled[75]    142.629355 2.3141526127 146.76969388     3.496939    39.696717    98.389535
times_uncensored_sampled[76]    141.537870 2.3556578143 141.71854389     4.164369    41.036196    97.474912
times_uncensored_sampled[77]    142.789706 2.2345569681 141.61350152     3.320894    41.049970    98.581153
times_uncensored_sampled[78]    141.608554 2.2874088398 145.15862940     3.696131    39.452500    96.741739
times_uncensored_sampled[79]    141.875960 2.3002275957 142.11608378     3.605607    41.345546    98.371112
times_uncensored_sampled[80]    139.954099 2.2339654009 138.80376281     3.411060    41.350382    99.820976
times_uncensored_sampled[81]    141.268911 2.3029753207 143.26361156     3.421019    42.084333    98.818513
times_uncensored_sampled[82]    138.764851 2.1987212521 137.35074391     4.032047    41.166599    96.670695
times_uncensored_sampled[83]    139.617770 2.2551969251 141.90792361     3.228154    39.116694    95.092211
times_uncensored_sampled[84]    140.148668 2.2332272135 140.87727358     3.576160    41.508313    98.389660
times_uncensored_sampled[85]    137.831297 2.1351378297 137.13560017     3.464388    41.893411    94.527528
times_uncensored_sampled[86]    139.983003 2.2657048584 140.94247945     3.841559    39.822481    97.614516
times_uncensored_sampled[87]    144.757120 2.4128285938 148.01969468     3.606300    41.781842    95.458402
times_uncensored_sampled[88]    140.990890 2.1654686932 140.33507450     3.419639    41.493472    97.629832
times_uncensored_sampled[89]    145.921362 2.3170988616 144.24825151     4.169803    43.331303   101.466607
times_uncensored_sampled[90]    140.358493 2.2680828749 140.33900450     3.549338    39.980115    97.431060
times_uncensored_sampled[91]    143.842424 2.2143370906 142.06935542     3.189280    43.072664   102.847611
times_uncensored_sampled[92]    139.873141 2.2306270928 142.23494177     3.584123    39.216249    96.967101
times_uncensored_sampled[93]    139.912440 2.2227518851 137.39576299     3.776574    42.638166    98.835073
times_uncensored_sampled[94]    139.834081 2.1615565760 137.42541861     3.332935    40.457600    97.961057
times_uncensored_sampled[95]    138.724614 2.1638193629 136.51607364     3.675221    41.484836    98.873942
times_uncensored_sampled[96]    142.287076 2.2966128224 143.56158186     3.396738    40.979858    95.996062
times_uncensored_sampled[97]    470.419346 7.9837002566 509.06508801    11.773704   126.328368   311.004290
times_uncensored_sampled[98]    139.959948 2.2722451610 140.96327159     3.139746    39.897990    94.151359
                                       75%         97.5%    n_eff      Rhat
beta[1]                          -1.030181    -0.7469734 2605.230 1.0000144
alpha                            -4.918897    -4.8704006 2972.334 0.9996976
times_uncensored_sampled[1]     194.722847   544.7175407 3741.977 1.0002579
times_uncensored_sampled[2]     191.291427   519.3235876 3918.262 1.0005511
times_uncensored_sampled[3]     196.518672   546.4008510 4083.497 0.9994523
times_uncensored_sampled[4]     193.782093   505.5158551 4098.812 0.9999343
times_uncensored_sampled[5]     198.737365   510.2748018 4005.278 0.9994101
times_uncensored_sampled[6]     193.659666   524.4831589 4023.574 1.0011622
times_uncensored_sampled[7]     185.200021   477.2215211 3813.437 0.9997368
times_uncensored_sampled[8]     190.985478   532.7925869 3904.831 1.0002433
times_uncensored_sampled[9]     195.758946   514.1863959 3917.756 0.9997543
times_uncensored_sampled[10]    194.029842   515.1145130 3956.721 0.9997372
times_uncensored_sampled[11]    198.316982   526.7202731 3885.710 1.0003604
times_uncensored_sampled[12]    195.615158   506.6888176 4037.613 1.0010929
times_uncensored_sampled[13]    187.061154   525.7366072 3900.173 1.0002023
times_uncensored_sampled[14]    196.689893   523.6898827 3921.981 0.9997125
times_uncensored_sampled[15]    195.328129   517.6530579 3835.257 1.0002486
times_uncensored_sampled[16]    198.708711   511.9756111 3964.458 0.9999847
times_uncensored_sampled[17]    193.512859   504.1426564 3600.440 0.9999645
times_uncensored_sampled[18]    197.015490   520.0228254 4145.128 0.9991648
times_uncensored_sampled[19]    196.057955   510.6657387 3871.694 1.0003096
times_uncensored_sampled[20]    197.979830   505.6724242 4063.490 0.9997836
times_uncensored_sampled[21]    194.925870   518.5482170 4034.845 0.9999531
times_uncensored_sampled[22]    653.117113  1832.5337493 3918.706 1.0009409
times_uncensored_sampled[23]    195.932539   525.3382515 3978.040 1.0005423
times_uncensored_sampled[24]    206.422917   518.9943582 4015.413 0.9999585
times_uncensored_sampled[25]    191.176451   517.4587949 3927.473 1.0010869
times_uncensored_sampled[26]    196.909205   531.5529741 3943.118 0.9996271
times_uncensored_sampled[27]    196.117142   504.1686498 4160.961 1.0000618
times_uncensored_sampled[28]    191.155639   506.8186895 3612.926 1.0003351
times_uncensored_sampled[29]    193.835243   486.1928822 4201.256 1.0006226
times_uncensored_sampled[30]    196.530145   522.0865005 3904.641 0.9998308
times_uncensored_sampled[31]    195.855445   506.0342162 4063.224 0.9994377
times_uncensored_sampled[32]    195.348347   518.6885084 4017.361 0.9998363
times_uncensored_sampled[33]    196.061779   532.7993697 3742.689 0.9998279
times_uncensored_sampled[34]    186.714730   511.8631378 4129.241 1.0002533
times_uncensored_sampled[35]    197.699866   521.3385446 3673.409 1.0012065
times_uncensored_sampled[36]    201.121379   521.0573119 4129.273 1.0008278
times_uncensored_sampled[37]    196.673057   530.6569772 3877.610 0.9994468
times_uncensored_sampled[38]    196.449584   531.0603176 4003.062 1.0006229
times_uncensored_sampled[39]    201.168646   530.7775481 3773.110 1.0001917
times_uncensored_sampled[40]    191.603003   513.6095604 3958.599 1.0000605
times_uncensored_sampled[41]    195.022251   523.3560914 3836.638 1.0001536
times_uncensored_sampled[42]    191.916065   540.0462562 3827.346 0.9999510
times_uncensored_sampled[43]    194.389521   538.2976611 4027.615 0.9993602
times_uncensored_sampled[44]    193.025329   508.2093261 3841.103 0.9996265
times_uncensored_sampled[45]    197.899550   519.0226432 3984.084 1.0014658
times_uncensored_sampled[46]    202.185342   519.5880000 4021.848 1.0003423
times_uncensored_sampled[47]    191.189760   492.2800113 3726.112 0.9997242
times_uncensored_sampled[48]    192.512622   533.2412469 3792.485 1.0001976
times_uncensored_sampled[49]    187.050975   498.1236910 3785.259 1.0008131
times_uncensored_sampled[50]    195.915948   517.0783742 3903.682 0.9997927
times_uncensored_sampled[51]    202.373265   536.7053141 3813.769 0.9995429
times_uncensored_sampled[52]    192.580362   518.6366276 3716.851 1.0002914
times_uncensored_sampled[53]    188.827135   508.3487346 4065.042 0.9999416
times_uncensored_sampled[54]    199.653185   521.4928734 4147.509 0.9996281
times_uncensored_sampled[55]    195.554488   520.2221845 3914.529 1.0002554
times_uncensored_sampled[56]    198.275347   507.7371683 4070.531 0.9993803
times_uncensored_sampled[57]    193.800933   518.2160677 3645.328 1.0003335
times_uncensored_sampled[58]    193.533381   519.7307073 3858.354 1.0000805
times_uncensored_sampled[59]    196.349982   523.4866306 4178.837 0.9995865
times_uncensored_sampled[60]    196.962282   519.2426750 3761.059 1.0013303
times_uncensored_sampled[61]    196.483394   511.4932501 4053.954 1.0006242
times_uncensored_sampled[62]    196.395327   517.4923775 4005.914 0.9991557
times_uncensored_sampled[63]    195.235397   529.0680127 3960.260 1.0002929
times_uncensored_sampled[64]    198.921567   546.3886705 3946.033 0.9994881
times_uncensored_sampled[65]    199.112186   516.8469292 3840.687 1.0007362
times_uncensored_sampled[66]    198.025819   507.8301701 3908.976 0.9993072
times_uncensored_sampled[67]    196.958175   519.0116644 4084.675 1.0001665
times_uncensored_sampled[68]    193.757877   512.7611460 4072.271 1.0003412
times_uncensored_sampled[69]    194.418574   495.6979017 4067.711 1.0000171
times_uncensored_sampled[70]    192.382341   498.4917020 4189.789 1.0003175
times_uncensored_sampled[71]    202.383992   509.6913037 3853.677 1.0016848
times_uncensored_sampled[72]    193.283661   509.9856382 3842.027 0.9997392
times_uncensored_sampled[73]    195.591551   507.6503816 4133.866 0.9991428
times_uncensored_sampled[74]    195.678953   532.7622822 3932.013 0.9994165
times_uncensored_sampled[75]    198.505232   528.2722019 4022.433 0.9998455
times_uncensored_sampled[76]    196.214057   513.9600898 3619.336 0.9995988
times_uncensored_sampled[77]    200.688180   528.8843342 4016.303 0.9992569
times_uncensored_sampled[78]    199.416033   513.7748692 4027.153 0.9997417
times_uncensored_sampled[79]    197.204535   520.4447863 3817.199 1.0004171
times_uncensored_sampled[80]    194.422347   502.3808021 3860.554 0.9997646
times_uncensored_sampled[81]    194.907026   525.2005559 3869.842 1.0007590
times_uncensored_sampled[82]    188.825220   514.4649608 3902.309 0.9995800
times_uncensored_sampled[83]    192.427976   527.5321306 3959.536 1.0005054
times_uncensored_sampled[84]    191.326174   531.0945005 3979.386 0.9997225
times_uncensored_sampled[85]    188.804720   517.0816622 4125.234 0.9995875
times_uncensored_sampled[86]    193.799880   510.2772908 3869.699 0.9998329
times_uncensored_sampled[87]    197.789495   560.4066912 3763.449 1.0006651
times_uncensored_sampled[88]    195.813505   519.1462247 4199.800 0.9992951
times_uncensored_sampled[89]    203.617845   532.8294237 3875.538 0.9998936
times_uncensored_sampled[90]    195.637353   531.5125612 3828.591 0.9996407
times_uncensored_sampled[91]    196.858494   535.5516533 4116.360 0.9999694
times_uncensored_sampled[92]    195.613063   517.2956382 4065.918 1.0000902
times_uncensored_sampled[93]    196.123833   490.2550804 3820.892 1.0001418
times_uncensored_sampled[94]    195.710189   498.9309295 4042.043 0.9999087
times_uncensored_sampled[95]    193.190470   496.0872204 3980.390 0.9995826
times_uncensored_sampled[96]    197.244313   529.2732345 3907.517 1.0005322
times_uncensored_sampled[97]    639.688318  1835.0538465 4065.727 1.0009428
times_uncensored_sampled[98]    191.507042   519.3876879 3848.589 0.9996612
 [ reached getOption("max.print") -- omitted 547 rows ]
exp_surv_model_draws <- tidybayes::tidy_draws(exp_surv_model_fit)
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
exp_surv_model_draws
## Constructor for Strata-specific survival function
construct_survival_function <- function(alpha, beta, x) {
    function(t) {
        lambda <- exp(alpha + x*beta)
        exp(-(lambda * t))
    }
}

## Random functions
exp_surv_model_surv_func <-
    exp_surv_model_draws %>%
    select(.chain, .iteration, .draw, alpha, `beta[1]`) %>%
    ## Simplify name
    rename(beta = `beta[1]`) %>%
    ## Construct realization of random functions
    mutate(`S(t|1)` = pmap(list(alpha, beta), function(a,b) {construct_survival_function(a,b,1)}),
           `S(t|0)` = pmap(list(alpha, beta), function(a,b) {construct_survival_function(a,b,0)}))
exp_surv_model_surv_func
times <- seq(from = 0, to = 165, by = 0.1)
times_df <- data_frame(t = times)

## Try first realizations
exp_surv_model_surv_func$`S(t|1)`[[1]](times[1:10])
 [1] 1.0000000 0.9997898 0.9995797 0.9993697 0.9991597 0.9989497 0.9987397 0.9985299 0.9983200 0.9981102
exp_surv_model_surv_func$`S(t|0)`[[1]](times[1:10])
 [1] 1.0000000 0.9992934 0.9985873 0.9978817 0.9971766 0.9964721 0.9957680 0.9950644 0.9943613 0.9936587
## Apply all realizations
exp_surv_model_survival <-
    exp_surv_model_surv_func %>%
    mutate(times_df = list(times_df)) %>%
    mutate(times_df = pmap(list(times_df, `S(t|1)`, `S(t|0)`),
                           function(df, s1, s0) {df %>% mutate(s1 = s1(t),
                                                               s0 = s0(t))})) %>%
    select(-`S(t|1)`, -`S(t|0)`) %>%
    unnest(cols = c(times_df)) %>%
    gather(key = Strata, value = survival, s1, s0) %>%
    mutate(Strata = factor(Strata, # Strata is whether or not something is hosted on multiple repos or not
                              levels = c("s1","s0"),
                              labels = c("multi repositories=Yes","multi repositories=No")))

## Average on survival scale
exp_surv_model_survival_mean <-
    exp_surv_model_survival %>%
    group_by(Strata, t) %>%
    summarize(survival_mean = mean(survival),
              survival_95upper = quantile(survival, probs = 0.975),
              survival_95lower = quantile(survival, probs = 0.025))
`summarise()` has grouped output by 'Strata'. You can override using the `.groups` argument.
exp_surv_model_survival
# plot the graphs
(ggplot(data = exp_surv_model_survival, mapping = aes(x = t, y = survival, color = Strata, group = interaction(.chain,.draw,Strata))) 
 + geom_line(size = 0.1, alpha = 0.02) 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_mean, group = Strata)) 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_95upper, group = Strata), linetype = "dotted") 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_95lower, group = Strata), linetype = "dotted")
 + scale_color_hue(direction = -1)
 + theme_bw()
 + theme(axis.text.x = element_text(angle = 90, vjust = 0.5), legend.key = element_blank(), plot.title = element_text(hjust = 0.5), strip.background = element_blank()))

LS0tCnRpdGxlOiAiQmF5ZXNpYW4gc3Vydml2YWwgYW5hbHlzaXMgdXNpbmcgbXVsdGlwbGUgcmVwb3NpdG9yaWVzIGFzIGEgcHJlZGljdG9yIgpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sKLS0tCmBgYHtyfQpsaWJyYXJ5KHJzdGFuKQpsaWJyYXJ5KHN1cnZpdmFsKQpsaWJyYXJ5KHRpZHl2ZXJzZSkKbGlicmFyeSh0aWR5YmF5ZXMpCmBgYAogCgpgYGB7cn0KIyBkYXRhLCBwYXJhbWV0ZXJzLCBtb2RlbCBhbmQgZ2VuZXJhdGVkIHF1YW50aXRpZXMgYmxvY2tzClN0YW5fZXhwb25lbnRpYWxfc3Vydml2YWxfbW9kZWwgPC0gIgpkYXRhewogIGludCA8bG93ZXI9MT4gTl91bmNlbnNvcmVkOwogIGludCA8bG93ZXI9MT4gTl9jZW5zb3JlZDsKICBpbnQgPGxvd2VyPTA+IG51bUNvdmFyaWF0ZXM7CiAgbWF0cml4W05fY2Vuc29yZWQsIG51bUNvdmFyaWF0ZXNdIFhfY2Vuc29yZWQ7CiAgbWF0cml4W05fdW5jZW5zb3JlZCwgbnVtQ292YXJpYXRlc10gWF91bmNlbnNvcmVkOwogIHZlY3RvciA8bG93ZXI9MD5bTl9jZW5zb3JlZF0gdGltZXNfY2Vuc29yZWQ7CiAgd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